﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Store.Bll;
using Store.Model.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Cors;

namespace Store.Server.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [EnableCors("any")]
    public class TypeeController : ControllerBase
    {
        private readonly TypeeBll bll;
        public TypeeController(TypeeBll _bll)
        {
            bll = _bll;
        }

        /// <summary>
        /// 显示商品信息
        /// </summary>
        /// <param name="sort"></param>
        /// <param name="state"></param>
        /// <param name="name"></param>
        /// <param name="brand"></param>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult Index(int page = 1, int limit = 20)
        {
            int total;
            var data = bll.GetTypeeList(page, limit, out total);
            return Ok(new { data = data, total = total});
        }



        /// <summary>
        /// 显示分类信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        //[HttpGet]
        //public List<Typee> GetCommodity(int id)
        //{
        //    return bll.GetTypee(id);
        //}

        /// <summary>
        /// 添加分类信息
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        [HttpPost]
        public int Add(Typee c)
        {
            return bll.TypeeAdd(c);
        }

        /// <summary>
        /// 修改分类信息
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        [HttpPost]
        public int Edit(Typee c)
        {
            return bll.UpdTypee(c);
        }

        /// <summary>
        /// 修改分类状态
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        //[HttpPost]
        //public int EditState(Commodity c)
        //{
        //    return bll.UpdComState(c);
        //}


        /// <summary>
        /// 删除分类信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public int Del(int id)
        {
            return bll.TypeeDel(id);
        }


        /// <summary>
        /// 批删
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpDelete]
        public int DelList(string[] ids)
        {
            return bll.TypeeDelList(ids);
        }


    }
}
